<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>路由传参props</title>
</head>
<body>
  <div id="app">
    <router-link to="/login">登录</router-link> |
    <router-link to="/register">注册</router-link> |
    <router-link to="/center">中心</router-link> 
    <router-view></router-view>
  </div>
  <!-- 定义模板 -->
  <template id="login">
    <div>
      <h1>我是登录组件</h1>
      <p>{{id}}</p>
    </div>
  </template>
  <template id="register">
    <div>
      <h1>我是注册组件</h1>
    </div>
  </template>
  <template id="center">
    <div>
      <h1>我是中心组件</h1>
    </div>
  </template>

  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
  <script>
    // 定义组件
    let Login = {
      template:'#login',
      props:{
        // props传参第1步：定义props配置项，配置项里面的键就是要接收数据的变量名
        id:Number,
        username:String
      }
    }
    let Register = {
      template:'#register'
    }
    let Center = {
      template:'#center'
    }

    // 定义路由列表
    let routes = [
      {
        path:'/login',
        name:'login',
        component:Login,
        // props传参第2步：开启props传参
        props:true
      },
      {
        path:'/register',
        name:'register',
        component:Register
      },
      {
        path:'/center',
        name:'center',
        component:Center
      }
    ]

    // 定义路由器
    let router = new VueRouter({
      routes
    })

    // 创建Vue实例
    const vm = new Vue({
      el:'#app',
      router,//绑定路由器
    })
  </script>
</body>
</html>